const app = getApp(); //引入导航

var util = require('../../utils/common.js'); //引入公共JS


var wxParse = require('../../wxParse/wxParse.js'); //引入


import { AddressList } from 'addressList.model.js';
var addressList = new AddressList();
var that;
Page({
  data: {
    showIcon: true,
    //显示返回键以及首页
    storage_arr: []
  },
  onShow: function () {},
  onLoad: function (options) {
    that = this;
    tt.getStorage({
      key: 'aid',
      success: function (res) {
        that.setData({
          aid: res.data
        });
      }
    });
    tt.getStorage({
      key: 'time',
      success: function (res) {
        that.setData({
          time: res.data
        });
      }
    });
    tt.getStorage({
      key: 'price',
      success: function (res) {
        that.setData({
          price: res.data
        });
      }
    });
    tt.getStorage({
      key: 'num',
      success: function (res) {
        that.setData({
          num: res.data
        });
      }
    });
    tt.getStorage({
      key: 'total',
      success: function (res) {
        that.setData({
          total: res.data
        });
      }
    });

    that._loadData();
  },
  _loadData: function () {
    addressList.getAddress(data => {
      console.log(data);

      if (data == 123) {
        that.setData({
          listfint: 0,
          listcount: data.length
        });
      } else {
        that.setData({
          listfint: data,
          listcount: data.length
        });
      }
    });
  },
  address_delete: function (e) {
    var that = this;
    var id = e.target.dataset.id;
    that.data.id = id;
    tt.showModal({
      title: '提示',
      content: '确定要删除吗？',
      success: function (sm) {
        if (sm.confirm) {
          addressList.getdelete(that.data.id, data => {
            if (data == 1) {
              tt.navigateTo({
                url: '../addressList2/addressList'
              });
            } else {
              tt.showToast({
                title: '请稍后再试',
                icon: 'error',
                duration: 2000,
                mask: true
              });
            }
          });
        }
      }
    });
  },
  address_count: function (e) {
    var count = e.target.dataset.count;

    if (count >= 5) {
      tt.showToast({
        title: '地址最多5条',
        icon: 'loading',
        duration: 1500
      });
    }
  },
  //分享
  onShareAppMessage: function () {
    return {
      title: '大河票务网小程序',
      desc: '大河票务网-购票安全放心保真!提供演唱会、音乐会、体育赛事、话剧歌剧、音乐节、相声曲艺等门票在线订票服务,订票电话400-800-7000',
      path: ''
    };
  }
});